{extend name="wap/default_new/base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/apply_statu.css">
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/components.css">
<style>
.apply .apply_type{
	margin-top:0;
	margin-bottom:0;
	height:40px;
	line-height:40px;
}
.apply-money{
	color:#f23c3c;
	font-size:15px;
}
.apply-p{
	color:#ff5400;
	
}
.apply_input{
	    width: 56%;
    padding: 5px;
}
.apply .apply_address {
    margin-top: 0;
    margin-bottom: 0;
    height: 40px;
    line-height: 40px;
}
.apply_address select{
	    padding: 5px;
}
</style>
{/block} 
{block name="goodsHead"}
<section class="head">
	<a class="head_back" href="javascript:window.history.go(-1)"><i class="icon-back"></i></a>
	<div class="head-title">区域代理申请</div>
</section>
{/block}
{block name="main"}

	{if condition="$shop_config['is_regional_agent'] eq 0"}<!-- 功能未开启 -->
	<div class="nothing-data" align="center">
		<img src="__TEMP__/{$style}/public/images/wap_nodata.png"/>
		<div>区域代理功能暂未开启，请联系管理人员。</div>
	</div>
	{else /}
	<div class="step-process" >
		<ul class="clear" id="ul" style="width: 306px;">
			<li class="step01 current">
				<p class="name ">申请区域代理</p>
				<span class="number">1</span>
				<span class="prcess-line prcess-line-r"></span>
			</li>
			{if condition="$agent_type eq 0 or $agent_type eq 1"}  <!-- 待审核 -->  
			<li class="current">
			{else /}
			<li>
			{/if}
				<p class="name">待审核</p>
				<span class="prcess-line prcess-line-l"></span>
				<span class="number">2</span>
				<span class="prcess-line prcess-line-r"></span>
			</li>
			{if condition="$agent_type eq 1"}  <!-- 已通过 -->
			<li class="step03 current">
			{else /}
			<li class="step03">
			{/if}
				<p class="name">申请成功</p>
				<span class="prcess-line prcess-line-l"></span>
				<span class="number">3</span>
			</li>
		</ul>
	</div>
	
	{if condition="$agent_type eq -1"}  <!-- 没申请过 -->
	<div class="apply">
		<p class="apply_type" >用户消费金额：
			<span class="apply-money" id="user_money">{$shop_sale_money}</span>
		</p>
		<p class="apply_type">区域代理类型：
			<select id="agent_type"  onchange = "change_apply_money();">
				<option value="1" data-money = {$region_config.application_require_province}>省代</option>
				<option value="2" data-money = {$region_config.application_require_city}>市代</option>
				<option value="3" data-money = {$region_config.application_require_district}>区代</option>
			</select>
		</p>
		<p class="apply_type" >
			&nbsp;&nbsp;真&nbsp;实&nbsp;姓&nbsp;名&nbsp;：&nbsp;
			<input type="text" id="user_name" class="apply_input">
		</p>
		<p class="apply_type" >&nbsp;&nbsp;联&nbsp;系&nbsp;电&nbsp;话&nbsp;：&nbsp;
			<input type="number" id="user_mobile" class="apply_input">
		</p>
		<p class="apply_address" >联系地址：
		<select id="seleAreaNext" onchange="GetProvince();" style="width:20%;">
			<option value="">选择省</option>
		</select>
			<select id="seleAreaThird" onchange="getSelCity();" style="width:20%;">
				<option value="">选择市</option>
			</select>
		<select id="seleAreaFouth" style="width:26%;">
				<option value="-1">选择区/县</option>
			</select>
		</p>
		<p class="apply-p"><i class="fa fa-info-circle" aria-hidden="true">&nbsp;&nbsp;最低消费<span id="apply_money">{$region_config.application_require_province}</span>元，才可成为<span id="apply_name">省代</span></i></p>
	</div>
	<a href="javascript:applySubmit();" class="a_button">申请区域代理</a>
	{elseif condition="$agent_type eq 0"/} <!-- 审核中 -->
	<div class="frog"><img src="__TEMP__/{$style}/public/images/agent_apply.png" >申请正在审核中......</div>
	<a href="{:__URL('APP_MAIN/distribution/distributionCenter','shop_id='.$shop_id)}" class="a_button">返回推广中心</a>
	
	{elseif condition="$agent_type eq 1"/} <!-- 已通过 -->
	<script type="text/javascript">
	location.href="{:__URL('APP_MAIN/member/index?shop_id='.$shop_id)}";
	</script>
	{/if}
{/if}

{/block}
{block name="bottom"}{/block}
{block name="javascript"} 
{if condition="$agent_type eq -1 && $shop_config['is_regional_agent'] neq 0"}  <!-- 没申请过 -->
<script src="__TEMP__/{$style}/public/js/address.js"></script>
{/if}
<script type="text/javascript">
var is_repeat = true;
function applySubmit(){
	var agent_type=$('#agent_type').val();
	var user_money = $("#user_money").text();
	var apply_money = $("#apply_money").text();
	var user_name = $("#user_name").val();
	var user_mobile = $("#user_mobile").val();
	var address = $('#seleAreaNext option:selected').text() + $('#seleAreaThird option:selected').text() + $('#seleAreaFouth option:selected').text();
	if(user_name == ''){
		layer.msg('姓名不能为空');
		return false;
	}
	if(user_mobile == ''){
		layer.msg('联系电话不能为空');
		return false;
	}
	var reg = /^\d{11}$/;
	if (!reg.test(user_mobile)) {
		layer.msg('请输入正确的手机号码');
		return false;
	} 
	if(address == '' || address=='请选择省选择市选择区/县'){
		layer.msg('联系地址不能为空');
		return false;
	}
	if(parseFloat(user_money) < parseFloat(apply_money)){
		layer.msg('用户消费不可小于申请区域代理最低消费');
		return false;
	}
	if(is_repeat){
		is_repeat = false;
		$.ajax({
			url: "{:__URL('APP_MAIN/distribution/applyregionalagent')}",
			type:'POST', //GET
			data:{
			'shop_id':'{$shop_id}',
			'agent_type':agent_type,
			'real_name':user_name,
			'mobile':user_mobile,
			'address':address
			},
			dataType:'json',//返回的数据格式：json/xml/html/script/jsonp/text
			success:function(retval){
				if(retval['code']>0){
					layer.msg('区域代理申请成功');
						 setTimeout(function(){
							 location.href="{:__URL('APP_MAIN/distribution/distributionCenter?shop_id='.$shop_id)}";
					},1000);
				}else{
					is_repeat = true;
					layer.msg('区域代理申请失败');
				}
			}
		})
	
	}else{
		layer.msg('正在申请中,不可重复提交!');
	}
}
function change_apply_money(){
	var apply_money = $("#agent_type option:checked").attr("data-money");
	var apply_name = $("#agent_type option:checked").text();
	$("#apply_money").text(apply_money);
	$("#apply_name").text(apply_name);
}
</script>
{/block}